import axios from "axios";
import {getSessionStorage} from "../common.js";

axios.defaults.baseURL = 'http://localhost:8080/elm/'

//登录
export const loginAPI=(loginData)=>{
    return axios.post("user/login",loginData)
}

//注册
export const registerAPI=(registerData)=>{
    return axios.post("user/register",registerData)
}


//根据关键字获取商家
export const getAllBusinessAPI=(kw='')=>{
    return axios.get(`business/getBusinesses?kw=${kw}`,)
}

//根据类型获取商家
export const getAllBusinessByOrderTypeAPI=(orderTypeId)=>{
    return axios.get(`business/getBusinessesByOrderTypeId/${orderTypeId}`)
}

//根据商家id获取商家
export const getBusinessByBusinessIdAPI=(businessId)=>{
    return axios.get(`business/getBusinessById/${businessId}`)
}

//根据商家id获取食物
export const getFoodsByBusinessIdAPI=(businessId)=>{
    return axios.get(`food/listFoodByBusinessId/${businessId}`)
}

//生成购物车
export const creatCartAPI=(token,cartData)=>{
    return axios.post(`cart/saveCart?token=${token}`,cartData)
}

//更新购物车
export const updateCartAPI=(token,cartData)=>{
    return axios.post(`cart/updateCart?token=${token}`,cartData)
}

//移除购物车
export const removeCartItemAPI=(token,cartData)=>{
    return axios.post(`cart/removeCartItem?token=${token}`,cartData)
}

//获取购物车全部内容
export const listCartAPI=(token,cartData)=>{
    return axios.post(`cart/listCart?token=${token}`,cartData)
}

//获取全部地址
export const getAddressByUserIdAPI=(token,userPhone)=>{
    return axios.get(`deliveryAddress/getAddressByUserId/${userPhone}?token=${token}`)
}

//获取一个地址
export const getDeliveryAddressByIdAPI=(token,deliveryAddressId)=>{
    return axios.get(`deliveryAddress/getDeliveryAddressById/${deliveryAddressId}?token=${token}`)
}

//添加地址
export const saveDeliveryAddressAPI=(token,deliveryAddressData)=>{
    return axios.post(`deliveryAddress/saveDeliveryAddress?token=${token}`,deliveryAddressData)
}

//更新地址
export const updateDeliveryAddressAPI=(token,deliveryAddressData)=>{
    return axios.post(`deliveryAddress/updateDeliveryAddress?token=${token}`,deliveryAddressData)
}

//删除一个地址
export const removeDeliveryAddressAPI=(token,deliveryAddressId)=>{
    return axios.get(`deliveryAddress/removeDeliveryAddress/${deliveryAddressId}?token=${token}`)
}

//新建一个订单
export const createOrdersAPI=(token,orderData)=>{
    return axios.post(`order/createOrders?token=${token}`,orderData)
}

//查询一个订单
export const getOrdersByIdAPI=(token,orderId)=>{
    return axios.get(`order/getOrdersById/${orderId}?token=${token}`)
}

//查询所有订单
export const listOrdersByUserIdAPI=(token,userPhone)=>{
    return axios.get(`order/listOrdersByUserId/${userPhone}?token=${token}`)
}

//完成支付，修改状态
export const updateOrderStateAPI=(token,orderId)=>{
    return axios.post(`order/updateOrderState?token=${token}`,orderId)
}
